<template>
    <div>
      <Form
        :label-width="110"
        ref="formValidate"
        :rules="ruleValidate"
        :model="formValidate"
        label-position="left"
      >
        <FormItem prop="unitName" label="数据字典类别">
          <i-input
            disabled
            type="text"
            :value="dictionaryGroupName"
          >
          </i-input>
        </FormItem>

        <FormItem label="数据字典名称" prop="dictionaryName">
          <i-input
            type="text"
            v-model="formValidate.itemName"
            placeholder="数据字典名称"
            :disabled="type === 3"
          >
          </i-input>
        </FormItem>
        <FormItem label="字典编号" >
          <i-input
            type="text"
            v-model="formValidate.itemCode"
            placeholder="字典编号"
            :disabled="type === 3"
          >
          </i-input>
        </FormItem>
        <FormItem  label="参数值">
          <i-input
            type="text"
            v-model="formValidate.itemValue"
            placeholder="参数值"
            :disabled="type === 3"
          >
          </i-input>
        </FormItem>
        <FormItem label="编辑状态" prop="state">
          <Select v-model="formValidate.state" clearable>
            <Option
             v-for="(item, index) in editList"
            :value="index" :key="index + 'diction'">{{item }}</Option>
          </Select>
        </FormItem>

        <FormItem label="上级字典">
          <Select v-model="formValidate.fkParentId" clearable>
            <Option v-for="item in dictionaryList" :value="item.id" :key="item.id" >{{ item.itemName
              }}</Option>
          </Select>
        </FormItem>
        <FormItem label="上级编号" >
          <i-input
            type="text"
            v-model="formValidate.parentCode"
            placeholder="上级编号"
            :disabled="type === 3"
          >
          </i-input>
        </FormItem>
        <FormItem label="排序" >
          <i-input
            type="number"
            v-model="formValidate.sortCode"
            placeholder="排序"
            :disabled="type === 3"
          >
          </i-input>
        </FormItem>

        <FormItem label="备注">
          <i-input
            type="textarea"
            v-model="formValidate.memo"
            placeholder="备注"
            :disabled="type === 3"
          >
          </i-input>
        </FormItem>
        <FormItem>
          <Button
            type="primary"
            @click="publicSubmit('formValidate')"
            v-if="type !== 3"
          >确定</Button>
          <Button @click="publicReset('formValidate')" style="margin-left: 8px">取消</Button>
        </FormItem>
      </Form>
    </div>
</template>

<script>
import { updateMixin } from '../../../mixin'
import API_KEY from '../../../api'
import { getDictionaryInfoByRootCode } from '../../../api/modules/system/dictionary'

export default {
  name: 'DictionaryManageUpdate',
  mixins: [updateMixin],
  props: {
    dictionaryGroupName: {
      type: String,
      default: ''
    },
    dictionaryGroupId: {
      type: [String, Number],
      required: true
    }
  },
  data: function () {
    return {
      formValidate: {
        memo: '',
        sortCode: '',
        itemValue: '',
        fkParentId: '',
        itemName: '',
        itemCode: '',
        parentCode: '',
        state: 1,
        rfRootCode: ''
      },
      editList: ['不可修改', '可修改', '禁用'],
      ruleValidate: {
        itemName: [{ required: true, message: '当前项不能为空', trigger: 'blur' }]
      },
      dictionaryList: [],
      action: {
        // 根据id获取数据（如果使用混入，属性名不能变，所在位置不能变,下同）
        readDataById: API_KEY.dictionary.curdDictionary,
        // 新增数据
        createData: API_KEY.dictionary.curdDictionary,
        // 更新数据
        updateData: API_KEY.dictionary.curdDictionary
      }
    }
  },

  mounted () {
    this.formValidate.rfRootCode = this.$props.dictionaryGroupId
    getDictionaryInfoByRootCode(this.formValidate.rfRootCode).then(({ data }) => {
      this.dictionaryList = data
    })
  }
}
</script>

<style scoped>

</style>
